package com.golxen.framework.event.condition.dao;


import com.golxen.framework.db.DBManager;
import com.golxen.framework.db.dao.AbstractDaoImpl;
import com.golxen.framework.event.condition.dao.entity.ConditionInfo;
import com.golxen.utils.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class ConditionDaoImpl extends AbstractDaoImpl {


	public Map<Integer, ConditionInfo> getTaskConditionInfoMap() {
		Map<Integer, ConditionInfo> infos = new HashMap<>();
		ResultSet rs = null;
		CallableStatement call = null;
		String sql = "select * from t_p_task_condition";
		try {
			getDb().setConnName(DBManager.configDbName);
			call = getDb().getConnection().prepareCall(sql);
			rs = call.executeQuery();
			while (rs.next()) {
				ConditionInfo conditionInfo = new ConditionInfo();
				conditionInfo.setConditionId(rs.getInt("id"));
				conditionInfo.setType(rs.getInt("type"));
				conditionInfo.setDesc(rs.getString("desc"));
				conditionInfo.setParamList(StringUtils.stringToBigIntegerList(rs.getString("params"), "\\|"));
				conditionInfo.setExtendParam(rs.getString("extendParam"));

				infos.put(conditionInfo.getConditionId(), conditionInfo);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			getDb().closeConnection(call, rs);
		}
		return infos;
	}
}
